<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ncduc
 * Date: 7/6/13
 * Time: 11:24 PM
 * To change this template use File | Settings | File Templates.
 */
function load_personal_information($userId,mysqli $mysqli, Smarty $smarty)
{
$lstUsers = $mysqli->query("SELECT * FROM thong_tin_ca_nhan AS ttcn LEFT  JOIN chuc_danh_khoa_hoc AS cdkh ON ttcn.MaCDKH=cdkh.Ma WHERE ttcn.MaUser={$userId}; ");
    if ($lstUsers != false) {
        $result = false;
        
        while ($row = $lstUsers->fetch_array(MYSQL_BOTH)) {

            $result = true;
            $smarty->assign('name', $row['HoTen']);
            $smarty->assign('gender', $row['GioiTinh']);
            $smarty->assign('birthday', $row['NTNS']);
            $smarty->assign('scientific_title_vi', $row['TenChucDanh_vi']);
            $smarty->assign('scientific_title_en', $row['TenChucDanh_en']);
            $smarty->assign('mainOrg_vi', $row['TenCoQuan_vi']);
            $smarty->assign('mainOrg_en', $row['TenCoQuan_en']);
            $smarty->assign('office_dept', $row['TenPhongBan']);
            $smarty->assign('address', $row['DiaChi']);
            $smarty->assign('city', $row['TenTinhThanh']);
            $smarty->assign('id_number', $row['CMND']);
            $smarty->assign('student_number', $row['MSSV']);
            $smarty->assign('trainee_number', $row['MaHocVien']);
            $smarty->assign('office_phone', $row['DienThoai']);
            $smarty->assign('mobile_phone', $row['DienThoaiDiDong']);
            $smarty->assign('bank_account', $row['SoTaiKhoan']);
            $smarty->assign('bank_name', $row['TenNganHang']);

     
        }
        if (!$result)
        {
            system_failed("no result", $smarty);
            return false;
        }
    }
    if ($mysqli->error)
    {
        system_failed($mysqli->error, $smarty);
        return false;
    }
    return true;
}
function load_educations($userId,mysqli $mysqli, Smarty $smarty)
{
  $query = "SELECT * FROM qua_trinh_dao_tao WHERE MaUser= {$userId}";
    $result = $mysqli->query($query);
    $arr_education = array();
    if ($result) {
        while ($row = $result->fetch_array(MYSQLI_BOTH)) {
            $arr_education[] = array('Ma' => $row['Ma'],
                'TenCoSoDaoTao_vi' => $row['TenCoSoDaoTao_vi'],
                'TenCoSoDaoTao_en' => $row['TenCoSoDaoTao_en'],
                'TuNgay' => $row['TuNgay'],
                'DenNgay' => $row['DenNgay'],
                'ChuyenNganh_vi' => $row['ChuyenNganh_vi'],
                'ChuyenNganh_en' => $row['ChuyenNganh_en'],
                'HocVi' => $row['HocVi'],
                'ChungChi_BangCap' => $row['ChungChi_BangCap']);
        }
    }
    if ($mysqli->error) {
        system_failed($mysqli->error, $smarty);
        $mysqli->close();
        return false;
    }
    $smarty->assign('educations', $arr_education);
    return true;
}
function load_employs($userId,mysqli $mysqli, Smarty $smarty)
{
 $query = "SELECT * FROM qua_trinh_cong_tac WHERE MaUser= {$userId}";
    $result = $mysqli->query($query);
    $arr_employ = array();
    if ($result) {
        while ($row = $result->fetch_array(MYSQLI_BOTH)) {
            $arr_employ[] = array('Ma' => $row['Ma'],
                'TenToChuc_vi' => $row['TenToChuc_vi'],
                'TenToChuc_en' => $row['TenToChuc_en'],
                'DiaChi' => $row['DiaChi'],
                'DienThoai' => $row['DienThoai'],
                'TuNgay' => $row['TuNgay'],
                'DenNgay' => $row['DenNgay'],
                'ChucVu_vi' => $row['ChucVu_vi'],
                'ChucVu_en' => $row['ChucVu_en'],
                'ThongTinThem' => $row['ThongTinThem']);
        }
    }
    if ($mysqli->error) {
        system_failed($mysqli->error, $smarty);
        $mysqli->close();
        return false;
    }
    $smarty->assign('works', $arr_employ);
    return true;
}
function load_research_activity($userId,mysqli $mysqli, Smarty $smarty)
{
     $query = "SELECT * FROM hoat_dong_nghien_cuu WHERE MaUser={$userId}";
    $result = $mysqli->query($query);
    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $id = $row['Ma'];
            $research_oriented_vi = $row['HuongNghienCuu_vi'];
            $research_oriented_en = $row['HuongNghienCuu_en'];
            $smarty->assign('id', $id);
            $smarty->assign('research_oriented_vi', $research_oriented_vi);
            $smarty->assign('research_oriented_en', $research_oriented_en);

        }
    }
    if ($mysqli->error) {
        system_failed($mysqli->error, $smarty);
        $mysqli->close();
        return false;
    }

    return true;
}
function load_research_projects($userId,mysqli $mysqli, Smarty $smarty)
{
 $query = "SELECT * FROM de_tai_nghien_cuu WHERE MaUser=$userId";

    $result = $mysqli->query($query);
    $arr_research_projects = array();
    if ($result) {

        while ($row = $result->fetch_assoc()) {

            $arr_research_projects[] = array("Ma" => $row["Ma"],
                "TenDeTai_vi" => $row["TenDeTai_vi"],
                "TenDeTai_en" => $row["TenDeTai_en"],
                "TenToChucTaiTro_vi" => $row["TenToChucTaiTro_vi"],
                "TenToChucTaiTro_en" => $row["TenToChucTaiTro_en"],
                "DiaChi" => $row["DiaChi"],
                "DiaChiWebsite" => $row["DiaChiWebsite"],
                "VaiTro_vi" => $row["VaiTro_vi"],
                "VaiTro_en" => $row["VaiTro_en"],
                "ThoiGianBatDau" => $row["ThoiGianBatDau"],
                "ThoiGianKetThuc" => $row["ThoiGianKetThuc"],
                "TongKinhPhi" => $row["TongKinhPhi"],
                "DonViTienTe" => $row["DonViTienTe"],
                "ThongTinThem" => $row["ThongTinThem"]);

        }

    }
    if ($mysqli->error) {
        system_failed($mysqli->error, $smarty);
        $mysqli->close();
        return false;
    }

    $smarty->assign('projects', $arr_research_projects);
    return true;
}

function load_research_results($userId,mysqli $mysqli, Smarty $smarty)
{
 $query = "SELECT * FROM ket_qua_nghien_cuu WHERE MaUser=$userId";
    $result = $mysqli->query($query);
    if ($result) {
        $arr_research_results = array();
        while ($row = $result->fetch_assoc()) {
            $arr_research_results[] = array("Ma" => $row["Ma"],
                "TenSanPham" => $row["TenSanPham"],
                "TenTacGia" => $row["TenTacGia"],
                "TenTapChi" => $row["TenTapChi"],
                "MaLoaiKQNghienCuu" => $row["MaLoaiKQNghienCuu"],
                "ISSN" => $row["ISSN"],
                "MinhChung" => $row["MinhChung"],
                "GhiChu" => $row["GhiChu"]
            );
        }
    }
    if ($mysqli->error) {
        system_failed($mysqli->error, $smarty);
        $mysqli->close();
        return false;
    }
    $smarty->assign('results', $arr_research_results);
    return true;
}

function load_more_infos($userId, mysqli $mysqli, Smarty $smarty)
{
    $query = "select * from thong_tin_them where MaUser = $userId";
    $result = $mysqli->query($query);
    if($result)
    {
        while ($row = $result->fetch_assoc())
        {
            $smarty->assign('id',$row['Ma']);
            $smarty->assign('read_en',$row['TiengAnh_Doc']);
            $smarty->assign('write_en',$row['TiengAnh_Viet']);
            $smarty->assign('speak_en',$row['TiengAnh_Noi']);
            $smarty->assign('read_other',$row['Khac_Doc']);
            $smarty->assign('write_other',$row['Khac_Viet']);
            $smarty->assign('speak_other',$row['Khac_Noi']);
            $smarty->assign('degree_en_uploaded',$row['ChungChi_Anh']);
            $smarty->assign('degree_other_uploaded',$row['ChungChi_Khac']);
            $smarty->assign('health',$row['TinhTrangSucKhoe']);
            $smarty->assign('health_uploaded',$row['GiayKhamSucKhoe']);
            $smarty->assign('drl_uploaded',$row['GiayCNDRL']);
            $smarty->assign('moreinfo_vi',$row['ThongTinThem_vi']);
            $smarty->assign('moreinfo_en',$row['ThongTinThem_en']);
        }
    }
    if($mysqli->error)
    {
        system_failed($mysqli->error . "sql: " . $query, $smarty);
        $mysqli->close();
        return false;
    }
    return true;
}
function load_social_activities($userId, mysqli $mysqli, Smarty $smarty)
{
    $query = "select * from hoat_dong_xa_hoi where MaUser=$userId";
    $result = $mysqli->query($query);
    if($result)
    {
        $social_activities = array();
        while ($row = $result->fetch_assoc())
        {
            $social_activities[] = array(
              'Ma' => $row['Ma'],
                'TenHoatDong' => $row['TenHoatDong'],
                'TuNgay' => $row['TuNgay'],
                'DenNgay' => $row['DenNgay'],
                'DiaChi' => $row['DiaChi'],
                'VaiTro' => $row['VaiTro'],
                'GiayChungNhan' => $row['GiayChungNhan'],
            );
        }
    }
    $smarty->assign('social_activities',$social_activities);
    if($mysqli->error)
    {
        return false;
    }
    return true;
}